gtest_dep = dependency('gtest', required: false)

test_sources = [
  # 'bus/test_i2c.cpp',
  'test_utils.cpp',
  'test_devmon.cpp',
  'main.cpp',

  'discovery/test_app_schema.cpp',
  'discovery/test_csr_parser.cpp',
  'discovery/test_csr_utils.cpp',
  'discovery/test_root_interface.cpp',

  'device/test_manager.cpp',
  'device/test_driver.cpp',
  'device/test_csr.cpp',
  'topology/test_topology.cpp',
  'topology/mock_topology_drivers.cpp',
  'topology/test_topology_discovery.cpp',
]

devmon_test = executable(
  'devmon_test',
  test_sources,
  include_directories: include_dirs + ['../src'],
  dependencies: [gtest_dep, libmcpp_deps, test_utilities_dep, devmon_dep],
  install: true,
  install_dir: install_dir,
)

# 设置测试环境变量，添加动态库搜索路径
lib_dir = meson.project_build_root() / 'usr/lib64'
run_command('mkdir', '-p', lib_dir, check: false)

# 追加子项目 component_drivers 的库目录，解决依赖库在子项目下找不到的问题
subproj_lib_dir = meson.project_build_root() / 'subprojects/component_drivers/usr/lib64'
run_command('mkdir', '-p', subproj_lib_dir, check: false)
test_env = environment()
if is_darwin
  test_env.set('DYLD_LIBRARY_PATH', lib_dir + ':' + subproj_lib_dir)
else
  test_env.set('LD_LIBRARY_PATH', lib_dir + ':' + subproj_lib_dir)
endif

if build_tests and meson_build
  custom_target(
    'copy_devmon_test',
    output: 'copy_devmon_test',
    command: ['cp', '-r', meson.current_source_dir() / 'tests_data', meson.project_build_root()],
    depends: devmon_test,
    build_by_default: true,
  )
endif
subdir('tests_data')


test('devmon_tests', devmon_test, env: test_env)

